<?php

/**
 * This is the model class for table "members".
 *
 * The followings are the available columns in table 'members':
 * @property string $id
 * @property string $guild_id
 * @property string $name
 * @property string $class_id
 * @property string $rank_id
 * @property string $race_id
 * @property integer $gender
 * @property string $joined_date
 * @property string $leave_date
 * @property string $email
 * @property string $external_url
 * @property string $comment
 * @property integer $hidden
 *
 * The followings are the available model relations:
 * @property Adjustments[] $adjustments
 * @property EventTransactions[] $eventTransactions
 * @property ItemTransactions[] $itemTransactions
 * @property MemberDetails[] $memberDetails
 * @property Races $race
 * @property Guilds $guild
 * @property Classes $class
 * @property Ranks $rank
 */
class Members extends CActiveRecord
{
	
        const GENDER_MALE = 0;
        const GENDER_FEMALE = 1;
    
        /**
	 * Returns the static model of the specified AR class.
	 * @return Members the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'members';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('guild_id, name, class_id, rank_id, race_id, gender, joined_date, hidden', 'required'),
			array('gender, hidden', 'numerical', 'integerOnly'=>true),
			array('guild_id, class_id, rank_id, race_id', 'length', 'max'=>10),
			array('name', 'length', 'max'=>128),
			array('email, external_url, comment', 'length', 'max'=>256),
			array('leave_date', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, guild_id, name, class_id, rank_id, race_id, gender, joined_date, leave_date, email, external_url, comment, hidden', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'adjustments' => array(self::HAS_MANY, 'Adjustments', 'member_id'),
			'eventTransactions' => array(self::HAS_MANY, 'EventTransactions', 'member_id'),
			'itemTransactions' => array(self::HAS_MANY, 'ItemTransactions', 'member_id'),
			'memberDetails' => array(self::HAS_MANY, 'MemberDetails', 'member_id'),
			'race' => array(self::BELONGS_TO, 'Races', 'race_id'),
			'guild' => array(self::BELONGS_TO, 'Guilds', 'guild_id'),
			'class' => array(self::BELONGS_TO, 'Classes', 'class_id'),
			'rank' => array(self::BELONGS_TO, 'Ranks', 'rank_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'guild_id' => 'Guild',
			'name' => 'Name',
			'class_id' => 'Class',
			'rank_id' => 'Rank',
			'race_id' => 'Race',
			'gender' => 'Gender',
			'joined_date' => 'Joined Date',
			'leave_date' => 'Leave Date',
			'email' => 'Email',
			'external_url' => 'External Url',
			'comment' => 'Comment',
			'hidden' => 'Hidden',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('guild_id',$this->guild_id,true);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('class_id',$this->class_id,true);
		$criteria->compare('rank_id',$this->rank_id,true);
		$criteria->compare('race_id',$this->race_id,true);
		$criteria->compare('gender',$this->gender);
		$criteria->compare('joined_date',$this->joined_date,true);
		$criteria->compare('leave_date',$this->leave_date,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('external_url',$this->external_url,true);
		$criteria->compare('comment',$this->comment,true);
		$criteria->compare('hidden',$this->hidden);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
        
        /**
         * Returns a list of gender options.
         * @return array
         */
        public function getGenderOptions() {
            return array(
                self::GENDER_MALE=>'Male',
                self::GENDER_FEMALE=>'Female',                    
            );
        }
}